<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Cliente extends AppModel {
    public $useTable = 'clientes';
    
    public function regresaBase(){
        return $this->getDataSource();
    }
    public function ultimoId()
    {
        $id = $this->find('first',array(
            'fields' => 'id',
            'order' => 'id DESC',
            'callbacks' => false,
          ));
        $id = $id['Cliente']['id'];
        return $id;
    }
    public function regresaTodos()
    {
        $t = $this->find('all',array(
            'order' => 'id ASC',
            'callbacks' => false,
          ));
        $todos = array();
        for($i = 0;$i<count($t);$i++)
            $todos[$i]=$t[$i]['Cliente'];
        return $todos;
    }
    public function regresaTodosNombres()
    {
        $t = $this->find('all',array(
            'fields'=>array('id','nombre','distribuidor'),
            'order' => 'id ASC',
            'callbacks' => false,
          ));
        $todos = array();
        for($i = 0;$i<count($t);$i++)
            $todos[$i]=$t[$i]['Cliente'];
        return $todos;
    }
    public function regresaCliente($id)
    {
        $c = $this->find('first',array(
            'conditions'=>array('id'=>$id),
            'callbacks' => false,
          ));
        $cliente = array();
        if(count($c)==1)
            $cliente = $c['Cliente'];
        return $cliente;
    }
}
?>
